package com.cskaoyan.javase.util;

import org.junit.Test;

import java.io.*;

/**
 * 测试工具类
 * @since 09:54
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class TestFileCopy {
    public static void main(String[] args) throws IOException {
        // BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream("E:\\1\\1copy.mp4"));
        // BufferedInputStream in = new BufferedInputStream(new FileInputStream("E:\\1\\1.mp4"));
        // FileCopyUtils.copyMultiByte(in, out);

        // 测试字符流对象复制文本文件
        InputStreamReader in = new InputStreamReader(new FileInputStream("E:\\\\1\\新垣结衣.txt"));
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream("E:\\1\\新垣结衣copy.txt"));
        BufferedReader bufIn = new BufferedReader(new FileReader("E:\\\\1\\新垣结衣.txt"));
        BufferedWriter bufOut = new BufferedWriter(new FileWriter("E:\\1\\新垣结衣copy.txt"));

        long time1 = System.currentTimeMillis();
        FileCopyUtils.copySingleChar(bufIn, bufOut);
        long time2 = System.currentTimeMillis();
        System.out.println(time2 - time1);
    }

    @Test
    public void test() throws IOException {
        InputStreamReader in = new InputStreamReader(new FileInputStream("E:\\\\1\\新垣结衣.txt"));
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream("E:\\1\\新垣结衣copy.txt"));
        FileCopyUtils.copyMultiChar(in, out);
    }


    @Test
    public void test2() throws IOException {
        BufferedReader bufIn = new BufferedReader(new FileReader("E:\\\\1\\新垣结衣.txt"), 32768);
        BufferedWriter bufOut = new BufferedWriter(new FileWriter("E:\\1\\新垣结衣copy.txt"), 32768);
        FileCopyUtils.copyMultiChar(bufIn, bufOut);
    }

    @Test
    public void test3() throws IOException {
        BufferedReader bufIn = new BufferedReader(new FileReader("E:\\\\1\\新垣结衣.txt"));
        BufferedWriter bufOut = new BufferedWriter(new FileWriter("E:\\1\\新垣结衣copy.txt"));
        char[] buf = new char[1024];
        int readCount;
        while ((readCount = bufIn.read(buf)) != -1) {
            bufOut.write(buf, 0, readCount);
        }
        bufOut.flush();
        bufOut.close();
        bufIn.close();
    }
}
